/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package infbmobile.comunicaciones;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.microedition.io.Connector;
import javax.microedition.io.HttpConnection;
import java.util.*;

/**
 *
 * @author inftel
 */
public class MedicamentosMovil implements Runnable {

private int longitudLista;
private Vector listaNombres=new Vector();
private Vector listaDefinicion=new Vector();

    public Vector getListaDefinicion() {
        return listaDefinicion;
    }

    public Vector getListaNombres() {
        return listaNombres;
    }

    public int getLongitudLista() {
        return longitudLista;
    }

    

    public void run() {
System.out.println("hebra lanzada");
        HttpConnection conexion = null;
        InputStream entrada = null;
        OutputStream salida= null;
        String nombre,definicion;



                try {
        String miUrl = "http://localhost:11296/GestionHospitalaria/MedicamentosServlet";
            try {
                conexion = (HttpConnection) Connector.open(miUrl);
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        conexion.setRequestProperty("Content-Language", "es-ES");
        conexion.setRequestProperty("User-Agent", "Profile/MIDP-2.0 Configuration/CLDC-1.0");
        conexion.setRequestProperty("Connection", "close");
        conexion.setRequestMethod(HttpConnection.GET);
                salida = conexion.openOutputStream();

        DataOutputStream out = new DataOutputStream(salida);
        out.writeUTF("medicamento");

        entrada = conexion.openInputStream();
        if (conexion.getResponseCode() == HttpConnection.HTTP_OK) {
            DataInputStream in = new DataInputStream(entrada);
            longitudLista=in.read();

            for (int i=0;i<longitudLista;i++){

            nombre = in.readUTF();
            definicion=in.readUTF();
            listaNombres.addElement(nombre);
            listaDefinicion.addElement(definicion);
          
         
            }
            for (int i=0;i<longitudLista;i++){
            System.out.println("Nombre :"+listaNombres.elementAt(i));
            System.out.println("Definicion :"+listaDefinicion.elementAt(i));
            }
            in.close();
        } else {
            /*    alert = new Alert("Error Conectando", error.toString(),
            null, AlertType.WARNING);
            alert.setTimeout(Alert.FOREVER);
            pantalla.setCurrent(alert);*/
        }
            entrada.close();
            conexion.close();

        } catch (IOException ex) {
        }




    }

}
